
/*=================================默认时间显示===========================*/

var defaultGetCarDate = new Date();
var defaultReturnCarDate = new Date();
// defaultGetCarDate.setHours(13)
defaultGetCarDate.setMinutes(0);
defaultReturnCarDate.setMinutes(0);
defaultReturnCarDate.setDate(defaultReturnCarDate.getDate()+1);


var defaultGetCarDateHours = defaultGetCarDate.getHours();

if(defaultGetCarDateHours >= 0 && defaultGetCarDateHours < 12){
    defaultGetCarDate.setHours(12);
    defaultReturnCarDate.setHours(12);
}else if(defaultGetCarDateHours >= 12 && defaultGetCarDateHours <15){
    defaultGetCarDate.setHours(15);
    defaultReturnCarDate.setHours(15);
}else if(defaultGetCarDateHours >= 15 && defaultGetCarDateHours<18) {
    defaultGetCarDate.setHours(18);
    defaultReturnCarDate.setHours(18);
}else{
    defaultGetCarDate.setHours(8);
    defaultGetCarDate.setDate(defaultGetCarDate.getDate() + 1);
    defaultReturnCarDate.setHours(8);
    defaultReturnCarDate.setDate(defaultReturnCarDate.getDate() + 1);
}

// 取车 年月日
$("#test-limit-one").attr("value",formatDate(defaultGetCarDate));
// 取车 时分
$("#test-limit-three").attr("value",formatTime(defaultGetCarDate));
// 还车 年月日
$("#test-limit-two").attr("value",formatDate(defaultReturnCarDate));
// 还车 时分
$("#test-limit-four").attr("value",formatTime(defaultReturnCarDate));

//
// $(".licar-namebox .car-introinfo .show-car-detail").click(function(){
//     var contentInnerHtml = document.querySelector(".content .show-car-hide");
//     contentInnerHtml.innerHTML +='    <div class="myshowbox">\n' +
//         '            <div class="myshowbox-container">\n' +
//         '                <a href="javascript:void(0)" class="btn-close"><span></span></a>\n' +
//         '                <div class="div-myshowbox" style="width: 940px; height: 600px;">\n' +
//         '                    <div class="common-modalBox">\n' +
//         '                        <div class="current-carname">\n' +
//         '                            <h3>'+'大众朗逸'+'</h3>\n' +
//         '                        </div>\n' +
//         '                    </div>\n' +
//         '                    <div class="current-carbox">\n' +
//         '                        <div class="current-carlist">\n' +
//         '                            <div class="current-carinfo">\n' +
//         '                                <div class="current-carpic">\n' +
//         '                                    <img src="http://r1nxp2i0y.hn-bkt.clouddn.com/images/red-car1.png" alt="">\n' +
//         '                                    <span class="video-playbtn video-li" data-cartypeids="421" id="carInfoVideo"></span>\n' +
//         '                                </div>\n' +
//         '                                <p>'+'大众朗逸'+'</p>\n' +
//         '                            </div>\n' +
//         '                            <ul class="current-carconfigure clear_float">\n' +
//         '                                <li id="li-first-child">\n' +
//         '                                    <p class="configure-name"><span class="configure-icon">\n' +
//         '                                    <img src="http://r1nxp2i0y.hn-bkt.clouddn.com/images/car-shift.png" alt=""></span></p>\n' +
//         '                                    <p>变速箱:<span>'+'自动'+'</span></p>\n' +
//         '                                </li>\n' +
//         '                                <li>\n' +
//         '                                    <p class="configure-name"><span class="configure-icon"><img src="http://r1nxp2i0y.hn-bkt.clouddn.com/images/car-tank-capacity.png" alt=""></span></p>\n' +
//         '                                    <p>油箱容量:<span>'+55+'</span></p>\n' +
//         '                                </li>\n' +
//         '                                <li>\n' +
//         '                                    <p class="configure-name"><span class="configure-icon"><img src="http://r1nxp2i0y.hn-bkt.clouddn.com/images/car-displacement.png" alt=""></span></p>\n' +
//         '                                    <p>排量:<span>'+1.6+'</span>L</p>\n' +
//         '                                </li>\n' +
//         '                                <li>\n' +
//         '                                    <p class="configure-name"><span class="configure-icon"><img src="http://r1nxp2i0y.hn-bkt.clouddn.com/images/car-seat-number.png" alt=""></span></p>\n' +
//         '                                    <p>座位数:<span>'+5+'</span></p>\n' +
//         '                                </li>\n' +
//         '                                <li>\n' +
//         '                                    <p class="configure-name"><span class="configure-icon"><img src="http://r1nxp2i0y.hn-bkt.clouddn.com/images/car-air-inlet-mode.png" alt=""></span></p>\n' +
//         '                                    <p>进气:<span>'+'自然吸气'+'</span></p>\n' +
//         '                                </li>\n' +
//         '                            </ul>\n' +
//         '                        </div>\n' +
//         '\n' +
//         '                    </div>\n' +
//         '                    <div class="current-carintro">\n' +
//         '                        <h3>车辆颜色说明</h3>\n' +
//         '                        <p>车辆颜色请以门店为准，图片仅为车型示意图。</p>\n' +
//         '                    </div>\n' +
//         '                </div>\n' +
//         '            </div>\n' +
//         '        </div>';
//
//         $(".show-car-hide .myshowbox .btn-close").click(function(){
//             $(".myshowbox").remove();
//         });
// });

/*==========================多条件动态查询===========================*/
/*A表示 '<a></a>' 标签*/
var chooseModelA = document.getElementById('choose-model').getElementsByTagName('a');
var chooseBrandA = document.getElementById('brandlist').getElementsByTagName('a');
var choosePriceA = document.getElementById('pricelist').getElementsByTagName('a');
var chooseGrarA = document.getElementById('grarlist').getElementsByTagName('a');
var chooseSeatA = document.getElementById('seatlist').getElementsByTagName('a');
var fieldOrderByA = document.getElementById('field-orderby').getElementsByTagName('a');

var oChooseModel = document.getElementById("choose-model");
var oChooseBrand = document.getElementById("brandlist");
var oChoosePrice = document.getElementById("pricelist");
var oChooseGrar = document.getElementById("grarlist");
var oChooseSeat = document.getElementById("seatlist");
var oFieldOrderBy = document.getElementById("field-orderby");

// chooseModelA[0].className = 'active';
// chooseBrandA[0].className = 'active';
// choosePriceA[0].className = 'active';
// chooseGrarA[0].className = 'active';
// chooseSeatA[0].className = 'active';
// fieldOrderByA[0].className = 'active';




for(var i = 0; i < chooseModelA.length;i++){
    chooseModelA[i].onclick = function(){
        var siblings = this.parentElement.children;
        for(var j=0;j<siblings.length;j++){
            siblings[j].className = '';
        }
        this.className = 'choose-model-active';
        if(this.parentNode == oChooseModel){
            getResult();
        }
    }
}

for(var i = 0; i < chooseBrandA.length;i++){
    chooseBrandA[i].onclick = function(){
        var siblings = this.parentElement.children;
        for(var j=0;j<siblings.length;j++){
            siblings[j].className = '';
        }
        this.className = 'active';
        if(  this.parentNode == oChooseBrand   ){
            getResult();
        }
    }
}

for(var i = 0; i < choosePriceA.length;i++){
    choosePriceA[i].onclick = function(){
        var siblings = this.parentElement.children;
        for(var j=0;j<siblings.length;j++){
            siblings[j].className = '';
        }
        this.className = 'active';
        if(this.parentNode == oChoosePrice ){
            getResult();
        }
    }
}

for(var i = 0; i < chooseGrarA.length;i++){
    chooseGrarA[i].onclick = function(){
        var siblings = this.parentElement.children;
        for(var j=0;j<siblings.length;j++){
            siblings[j].className = '';
        }
        this.className = 'active';
        if(this.parentNode == oChooseGrar  ){
            getResult();
        }
    }
}

for(var i = 0; i < chooseSeatA.length;i++){
    chooseSeatA[i].onclick = function(){
        var siblings = this.parentElement.children;
        for(var j=0;j<siblings.length;j++){
            siblings[j].className = '';
        }
        this.className = 'active';
        if(this.parentNode ==  oChooseSeat  ){
            getResult();
        }
    }
}


for(var i = 0; i < fieldOrderByA.length;i++){
    fieldOrderByA[i].onclick = function(){
        var siblings = this.parentElement.parentElement.children;
        for(var j=0;j<siblings.length;j++){
            siblings[j].firstElementChild.className = '';
        }
        this.className = 'field-orderby-active';
        if(
            this.parentNode.parentNode == oFieldOrderBy ){
            getResult();
        }
    }
}
$(".submit-btn").click(function (){
    getResult();
})

function getResult(){
    var o1 = 0, o2 = 0, o3 =0 , o4 = 0, o5 = 0, o6 = 0;
    for(var i=0; i<chooseModelA.length; i++){
        if(chooseModelA[i].className == 'choose-model-active'){
            o1 = i;
        }
    }
    for(var i=0; i<chooseBrandA.length; i++){
        if(chooseBrandA[i].className == 'active'){
            o2 = i;
        }
    }
    for(var i=0; i<choosePriceA.length; i++){
        if(choosePriceA[i].className == 'active'){
            o3 = i;
        }
    }
    for(var i=0; i<chooseGrarA.length; i++){
        if(chooseGrarA[i].className == 'active'){
            o4 = i;
        }
    }
    for(var i=0; i<chooseSeatA.length; i++){
        if(chooseSeatA[i].className == 'active'){
            o5 = i;
        }
    }
    for(var i=0; i<fieldOrderByA.length; i++){
        if(fieldOrderByA[i].className == 'field-orderby-active'){
            o6 = i;
        }
    }


    var borrowStoreId = $("#borrow-store-id").text();
    var returnStoreId = $("#return-store-id").text();

    var getCarDate = $("#test-limit-one").val();
    var getCarTime = $("#test-limit-three").val();
    var returnCarDate = $("#test-limit-two").val();
    var returnCarTime = $("#test-limit-four").val();
    getCarTime = getCarDate+" " + getCarTime;

    returnCarTime = returnCarDate + " " +returnCarTime;
    var returnCarTime2 = new Date(returnCarTime);

    returnCarTime2 = returnCarTime2.setHours(returnCarTime2.getHours()-9);
    getCarTime = new Date(getCarTime);
    if(new Date(getCarTime) <= new Date()){
        alert("取车时间不能小于当前时间~");
    }else if(new Date(getCarTime) >= returnCarTime2){
        alert("取车时间与还车时间间隔不能小于九个小时~");
    }

    var carType = chooseModelA[o1].firstElementChild.firstElementChild.textContent;
    var carBrand = chooseBrandA[o2].text;
    var carDailyPrice = choosePriceA[o3].text;
    var carShiftType = chooseGrarA[o4].text;
    var carSeatNumber = chooseSeatA[o5].text;
    var orderBy = fieldOrderByA[o6].text;
    // var pageNum = chooseBrandA[o2].text;


    /*showCarList(carType, carBrand,
        carDailyPrice,
        carShiftType, carSeatNumber,
        orderBy,1)*/
    showCarListByContainAndStore(
        borrowStoreId,
        getCarTime,
        carType,
        carBrand,
        carDailyPrice,
        carShiftType,
        carSeatNumber,orderBy,1)
}



/*===================时间=====================*/
layui.use('laydate', function(){
    var laydate = layui.laydate;

    //常规用法
    laydate.render({
        elem: '#test1'
    });

    //国际版
    laydate.render({
        elem: '#test1-1'
        ,lang: 'en'
    });

    //年选择器
    laydate.render({
        elem: '#test2'
        ,type: 'year'
    });

    //年月选择器
    laydate.render({
        elem: '#test3'
        ,type: 'month'
    });

    //时间选择器
    laydate.render({
        elem: '#test4'
        ,type: 'time'
    });

    //日期时间选择器
    laydate.render({
        elem: '#test5'
        ,type: 'datetime'
    });

    //日期范围
    laydate.render({
        elem: '#test6'
        //设置开始日期、日期日期的 input 选择器
        //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
        ,range: ['#test-startDate-1', '#test-endDate-1']
    });

    //年范围
    laydate.render({
        elem: '#test7'
        ,type: 'year'
        ,range: true
    });

    //年月范围
    laydate.render({
        elem: '#test8'
        ,type: 'month'
        ,range: true
    });

    //时间范围
    laydate.render({
        elem: '#test9'
        ,type: 'time'
        ,range: true
    });

    //日期时间范围
    laydate.render({
        elem: '#test10'
        ,type: 'datetime'
        ,range: true
    });

    //自定义格式
    laydate.render({
        elem: '#test11'
        ,format: 'yyyy年MM月dd日'
    });
    laydate.render({
        elem: '#test12'
        ,format: 'dd/MM/yyyy'
    });
    laydate.render({
        elem: '#test13'
        ,format: 'yyyyMMdd'
    });
    laydate.render({
        elem: '#test14'
        ,type: 'time'
        ,format: 'H点m分'
    });
    laydate.render({
        elem: '#test15'
        ,type: 'month'
        ,range: '~'
        ,format: 'yyyy-MM'
    });
    laydate.render({
        elem: '#test16'
        ,type: 'datetime'
        ,range: '到'
        ,format: 'yyyy年M月d日H时m分s秒'
    });

    //开启公历节日
    laydate.render({
        elem: '#test17'
        ,calendar: true
    });

    //自定义重要日
    laydate.render({
        elem: '#test18'
        ,mark: {
            '0-10-14': '生日'
            ,'0-12-31': '跨年' //每年的日期
            ,'0-0-10': '工资' //每月某天
            ,'0-0-15': '月中'
            ,'2017-8-15': '' //如果为空字符，则默认显示数字+徽章
            ,'2099-10-14': '呵呵'
        }
        ,done: function(value, date){
            if(date.year === 2017 && date.month === 8 && date.date === 15){ //点击2017年8月15日，弹出提示语
                layer.msg('这一天是：中国人民抗日战争胜利72周年');
            }
        }
    });

    var minDate = new Date();
    var maxDate = new Date();
    maxDate = maxDate.setDate(maxDate.getDate()+60);
    maxDate = new Date(maxDate)

    //限定可选日期
    var ins22 = laydate.render({
        elem: '#test-limit-one'
        ,min: formatDate(minDate)
        ,max: formatDate(maxDate)
    });
    /*================注意还车时间必须大于租车时间（未实现）==============*/
    var minDate2 = new Date();
    var maxDate2 = new Date();
    minDate2 = minDate2.setDate(minDate2.getDate()+1);
    maxDate2 = maxDate2.setDate(maxDate.getDate()+60);
    minDate2 = new Date(minDate2);
    maxDate2 = new Date(maxDate2);
    // $(".car-time").attr("placeholder","20:30:22");

    var ins22 = laydate.render({
        elem: '#test-limit-two'
        ,min: formatDate(minDate2)
        ,max: formatDate(maxDate2)
    });
/*定位*/

    //前后若干天可选，这里以7天为例
    laydate.render({
        elem: '#test-limit2'
        ,min: -7
        ,max: 7
    });

    //限定可选时间
    laydate.render({
        elem: '#test-limit-three'
        ,type: 'time'
        ,min: '8:00:00'
        ,max: '18:00:00'
        ,format: 'H:m'
        ,btns: ['clear', 'confirm']
    });
    laydate.render({
        elem: '#test-limit-four'
        ,type: 'time'
        ,format: 'H:m'
        ,min: '8:00:00'
        ,max: '18:00:00'
        ,btns: ['clear', 'confirm']
    });


    //同时绑定多个
    lay('.test-item').each(function(){
        laydate.render({
            elem: this
            ,trigger: 'click'
        });
    });

    //初始赋值
    laydate.render({
        elem: '#test19'
        ,value: '1989-10-14'
        ,isInitValue: true
    });

    //选中后的回调
    laydate.render({
        elem: '#test20'
        ,done: function(value, date){
            layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
        }
    });

    //日期切换的回调
    laydate.render({
        elem: '#test21'
        ,change: function(value, date){
            layer.msg('你选择的日期是：' + value + '<br><br>获得的对象是' + JSON.stringify(date));
        }
    });
    //不出现底部栏
    laydate.render({
        elem: '#test22'
        ,showBottom: false
    });

    //只出现确定按钮
    laydate.render({
        elem: '#test23'
        ,btns: ['confirm']
    });

    //自定义事件
    laydate.render({
        elem: '#test24'
        ,trigger: 'mousedown'
    });

    //点我触发
    laydate.render({
        elem: '#test25'
        ,eventElem: '#test25-1'
        ,trigger: 'click'
    });

    //双击我触发
    lay('#test26-1').on('dblclick', function(){
        laydate.render({
            elem: '#test26'
            ,show: true
            ,closeStop: '#test26-1'
        });
    });

    //日期只读
    laydate.render({
        elem: '#test27'
        ,trigger: 'click'
    });

    //非input元素
    laydate.render({
        elem: '#test28'
    });

    //墨绿主题
    laydate.render({
        elem: '#test29'
        ,theme: 'molv'
    });

    //自定义颜色
    laydate.render({
        elem: '#test30'
        ,theme: '#393D49'
    });

    //格子主题
    laydate.render({
        elem: '#test31'
        ,theme: 'grid'
    });


    //直接嵌套显示
    laydate.render({
        elem: '#test-n1'
        ,position: 'static'
    });
    laydate.render({
        elem: '#test-n2'
        ,position: 'static'
        ,lang: 'en'
    });
    laydate.render({
        elem: '#test-n3'
        ,type: 'month'
        ,position: 'static'
    });
    laydate.render({
        elem: '#test-n4'
        ,type: 'time'
        ,position: 'static'
    });
});


/*====================分页=================*/
// layui.use(['laypage', 'layer'], function(){
//     var laypage = layui.laypage
//         ,layer = layui.layer;
//
//     //总页数低于页码总数
//     laypage.render({
//         elem: 'demo0'
//         ,count: 50 //数据总数
//     });
//
//     //总页数大于页码总数
//     laypage.render({
//         elem: 'demo1'
//         ,count: 70 //数据总数
//         ,jump: function(obj){
//             console.log(obj)
//         }
//     });
//
//     //自定义样式
//     laypage.render({
//         elem: 'demo2'
//         ,count: 100
//         ,theme: '#1E9FFF'
//     });
//     laypage.render({
//         elem: 'demo2-1'
//         ,count: 100
//         ,theme: '#FF5722'
//     });
//     laypage.render({
//         elem: 'demo2-2'
//         ,count: 100
//         ,theme: '#FFB800'
//     });
//
//     //自定义首页、尾页、上一页、下一页文本
//     laypage.render({
//         elem: 'demo3'
//         ,count: 100
//         ,first: '首页'
//         ,last: '尾页'
//         ,prev: '<em>←</em>'
//         ,next: '<em>→</em>'
//     });
//
//     //不显示首页尾页
//     laypage.render({
//         elem: 'demo4'
//         ,count: 100
//         ,first: false
//         ,last: false
//     });
//
//     //开启HASH
//     laypage.render({
//         elem: 'demo5'
//         ,count: 500
//         ,curr: location.hash.replace('#!fenye=', '') //获取hash值为fenye的当前页
//         ,hash: 'fenye' //自定义hash值
//     });
//
//     //只显示上一页、下一页
//     laypage.render({
//         elem: 'demo6'
//         ,count: 50
//         ,layout: ['prev', 'next']
//         ,jump: function(obj, first){
//             if(!first){
//                 layer.msg('第 '+ obj.curr +' 页');
//             }
//         }
//     });
//
//     //完整功能
//     laypage.render({
//         elem: 'demo7'
//         ,count: 100
//         ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
//         ,jump: function(obj){
//             console.log(obj)
//         }
//     });
//
//     //自定义排版
//     laypage.render({
//         elem: 'demo8'
//         ,count: 1000
//         ,layout: ['limit', 'prev', 'page', 'next']
//     });
//     laypage.render({
//         elem: 'demo9'
//         ,count: 1000
//         ,layout: ['prev', 'next', 'page']
//     });
//     laypage.render({
//         elem: 'demo10'
//         ,count: 1000
//         ,layout: ['page', 'count']
//     });
//
//     //自定义每页条数的选择项
//     laypage.render({
//         elem: 'demo11'
//         ,count: 1000
//         ,limit: 100
//         ,limits: [100, 300, 500]
//     });
//
//
//     //将一段数组分页展示
//
//     //测试数据
//     var data = [
//         '北京',
//         '上海',
//         '广州',
//         '深圳',
//         '杭州',
//         '长沙',
//         '合肥',
//         '宁夏',
//         '成都',
//         '西安',
//         '南昌',
//         '上饶',
//         '沈阳',
//         '济南',
//         '厦门',
//         '福州',
//         '九江',
//         '宜春',
//         '赣州',
//         '宁波',
//         '绍兴',
//         '无锡',
//         '苏州',
//         '徐州',
//         '东莞',
//         '佛山',
//         '中山',
//         '成都',
//         '武汉',
//         '青岛',
//         '天津',
//         '重庆',
//         '南京',
//         '九江',
//         '香港',
//         '澳门',
//         '台北'
//     ];
//
//     //调用分页
//     laypage.render({
//         elem: 'demo20'
//         ,count: data.length
//         ,jump: function(obj){
//             //模拟渲染
//             document.getElementById('biuuu_city_list').innerHTML = function(){
//                 var arr = []
//                     ,thisData = data.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
//                 layui.each(thisData, function(index, item){
//                     arr.push('<li>'+ item +'</li>');
//                 });
//                 return arr.join('');
//             }();
//         }
//     });
//
// });

// 格式化时间
function formatDate(date) {
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    return (y + '-' + m + '-' + d);
};


function formatTime(time){
    return time.getHours() + ':' + time.getMinutes();
}
function formatTimeU(time){
    return time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds();
}
